<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<!DOCTYPE html>
<html>
<head>
<title>洗衣服务</title>
<jsp:include page="../../views/layout/inc.jsp"></jsp:include>

<script type="text/javascript">

	$.canEdit = true;
	$.canDelete = true;
	var dataGrid;
	$(function() {
		var residenceId = '${residenceId}';
		showXiyi(residenceId);
	 	/* var status = '${param.status}';
		alert(status);
		$('#status').combobox('setValue','8');
		
  */
		dataGrid = $('#dataGrid').datagrid({
			url : '/xiyiOrderController/dataGrid',
			singleSelect : true,
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'id',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			nowrap : false,
			frozenColumns : [ [ {
				field : 'residenceId',
				title : '所属小区',
				width : 60,
				hidden : true
			}] ],
			columns : [ [ {
				field : 'residenceName',
				title : '所属小区',
				width : 70,
				align:'center'
			},{
				field : 'orderType',
				title : '订单类型',
				width : 70,
				align:'center',
				formatter:function(val,rec){ 
					if(val == 1) {
						return '收快递';
					}else if(val == 2) {
						return '发快递';
					}else if(val == 3) {
						return '洗衣';
					}
				}
			},{
				field : 'outBizNum',
				title : '洗衣面单',
				width : 100,
				align:'center',
				sortable : true
			},{
				field : 'name',
				title : '订单名称',
				width : 100,
				align:'center',
				sortable : true
			},{
				field : 'companyId',
				title : '洗衣店Id',
				align:'center',
				width : 60,
				hidden : true
			},{
				field : 'laundryName',
				title : '洗衣店',
				align:'center',
				width : 100
			},{
				field : 'khName',
				title : '客户名称',
				align:'center',
				width : 80
			},{
				field : 'khMobile',
				title : '客户电话',
				align:'center',
				width : 80
			},{
				field : 'amount',
				title : '订单费用(元)',
				align:'center',
				width : 100,
				formatter:function(val,rec){ 
					if(val > 0) {
						return val/100;
					}
				}
			}, {
				field : 'status',//代洗衣物：1待处理、5已取件、7已送洗、8待取、2完成、3关闭、4删除
				title : '订单状态',
				align:'center',
				width : 60,
				formatter:function(val,rec){ 
					if(val == 0) {
						return '';
					}else if(val == 1) {
						return '待处理';
					}else if(val == 2) {
						return '完成';
					}else if(val == 3) {
						return '关闭';
					}else if(val == 4) {
						return '删除';
					}else if(val == 5) {
						return '已取件';
					}else if(val == 7) {
						return '已送洗';
					}else if(val == 8) {
						return '待取';
					}
				}
			}, {
				field : 'paymentStatus',//支付状态,1:未支付;2:已现金支付;3:已线上支付
				title : '支付状态',
				align:'center',
				width : 60,
				formatter:function(val,rec){ 
					if(val == 0) {
						return '';
					}else if(val == 1) {
						return '未支付';
					}else if(val == 2) {
						return '已现金支付';
					}else if(val == 3) {
						return '已线上支付';
					}
				}
			}, {
				field : 'gmtCreate',
				title : '创建时间',
				align:'center',
				width : 120,
				formatter:function(val,rec){
					if(val!='' && val!=null){
						 var unixTimestamp = new Date(val);  
	                     return unixTimestamp.format('yyyy-MM-dd hh:mm:ss'); 
					}
				}
			}, {
				field : 'gmtModify',
				title : '更新时间',
				align:'center',
				width : 100,
				formatter:function(val,rec){
					if(val!='' && val!=null){
						 var unixTimestamp = new Date(val);  
	                     return unixTimestamp.format('yyyy-MM-dd hh:mm:ss'); 
					}
				}
			},{
				field : 'remark',
				title : '备注',
				align:'center',
				width : 100
			},{field:'action',title:'操作',width:60,formatter : function(value, row, index) {
					var str = '';
					if ($.canEdit) {
						str += $.formatString('<img onclick="editXiyiServer(\'{0}\');" src="{1}" title="编辑"/>', index, '${path}/images/extjs_icons/pencil.png');
					}
					str += '&nbsp;';
					if ($.canDelete) {
						str += $.formatString('<img onclick="delDeviceBase(\'{0}\');" src="{1}" title="删除"/>', index, '${path}/images/extjs_icons/cancel.png');
					}
					return str;
				}}
			] ],
			toolbar : '#toolbar',
			onContextMenu : function(e, row) {
				e.preventDefault();
				$(this).datagrid('unselectAll').datagrid('uncheckAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			},
			onLoadSuccess : function() {
				$('#searchForm table').show();
				parent.$.messager.progress('close');
				$(this).datagrid('tooltip');
			},
			onDblClickRow : function(rowIndex, rowData){
				editXiyiServer(rowIndex);
			}
		});
		
		
		<c:if test="${not empty param}">
		dataGrid.datagrid('load', {"status":"${param.status}"});
		</c:if> 
		
		document.onkeydown = function(e) {
			var theEvent = window.event || e;
			var code = theEvent.keyCode || theEvent.which;
			if (code == 13) {
				searchFun();
			}
		}
	});

	
	function showXiyi(residenceId){
		//洗衣店下拉
		$.ajax({
			type:'post',
			url:'/companyLaundryController/getCombobox?residenceId='+residenceId,
			data:{},
			success:function(result) {
				$('.companyId').combobox({
					data : result,
					valueField:'value',   
				    textField:'text',
				    panelHeight:'auto'
				});
				sessionStorage.setItem("comboboxExpress", JSON.stringify(result));
			},
			dataType:'json'
		});
	}
	
	
	function searchFun() {
		dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
	}
	function cleanFun() {
		$('#searchForm input').val('');
		dataGrid.datagrid('load', {});
	}
	
	//新增洗衣订单
	function addMainXiyi() {
		parent.$.modalDialog({
			title : '代洗衣订单--新增',
			width : 700,
			height : 400,
			href : '/xiyiOrderController/addPage',
			buttons : [ {
				text : ' 确定 ',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			} ]
		});
	}
	
	//订单通知
	function orderNotice(){
		var row = dataGrid.datagrid('getSelected');
		if (row) { 
		 	if(row.status!=8){
		 		parent.$.messager.alert('提示', "只有【取件】状态的订单才能通知", 'info');
		 		return;
			} 
			parent.$.messager.confirm('询问', '确认要通知客户?', function(b) {
				if (b) {
					parent.$.messager.progress({
						title : '提示',
						text : '数据处理中，请稍后....'
					});
					$.post('/xiyiOrderController/orderNotice', {
						id : row.id
					}, function(result) {
						if (result.success) {
							parent.$.messager.alert('提示', result.msg, 'info');
							dataGrid.datagrid('reload');
						}else{
							parent.$.messager.alert('提示',result.msg,'info');
						}
						parent.$.messager.progress('close');
					}, 'JSON');
				}
			});
		}else{
			parent.$.messager.alert('提示','请选择要通知的订单','info');
		}
	}
	
	//取件短信通知
	function orderSms(){
		var row = dataGrid.datagrid('getSelected');
		if (row) {
			alert(row.status);
		 	if(row.status!=8){
		 		parent.$.messager.alert('提示', "只有【取件】状态的订单才能通知", 'info');
		 		return;
			} 
			parent.$.messager.confirm('询问', '确认要发送短信通知客户?', function(b) {
				if (b) {
					parent.$.messager.progress({
						title : '提示',
						text : '数据处理中，请稍后....'
					});
					$.post('/xiyiOrderController/orderNotice', {
						id : row.id
					}, function(result) {
						if (result.success) {
							parent.$.messager.alert('提示', result.msg, 'info');
							dataGrid.datagrid('reload');
						}else{
							parent.$.messager.alert('提示',result.msg,'info');
						}
						parent.$.messager.progress('close');
					}, 'JSON');
				}
			});
		}else{
			parent.$.messager.alert('提示','请选择要通知的订单','info');
		}
	}
	
	
	//修改
	function editXiyiServer(index){
		dataGrid.datagrid("selectRow",index);
		var row = dataGrid.datagrid('getSelected');
		if (row) {
			/* if(row.status=="1"){//待处理的工单才能修改
				
			}else{
				parent.$.messager.alert('提示','订单处理中，只能修改【订单状态】','info');
			} */
			if(row.status == 2){
				parent.$.messager.alert('提示', '该记录已经完成!', 'info');
				return false;
			}
			parent.$.modalDialog({
				title : '订单信息--修改',
				width : 500,
				height : 400,
				href : '/xiyiOrderController/editPage?id=' + row.id,
				buttons : [ {
					text : '确定',
					handler : function() {
						parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
						var f = parent.$.modalDialog.handler.find('#form');
						f.submit();
					}
				} ]
			});
			
		}
	}
	
	
	//删除
	function delDeviceBase(index){
		dataGrid.datagrid("selectRow",index);
		var row = dataGrid.datagrid('getSelected');
		if (row) {
			if(row.status!=1){
				parent.$.messager.alert('提示', "该订单状态不能删除", 'info');return;
			}
			parent.$.messager.confirm('询问', '是否确认删除所选择订单，删除后无法恢复!', function(b) {
				if (b) {
					parent.$.messager.progress({
						title : '提示',
						text : '数据处理中，请稍后....'
					});
					var url = '/xiyiOrderController/deleteOrder?id=' + row.id;
					$.ajax({
						type:'post',
						url:url,
						data:{},
						success:function(result) {
							if (result.success) {
								parent.$.messager.alert('提示', result.msg, 'info');
								dataGrid.datagrid('reload');
							}else{
								parent.$.messager.alert('提示',result.msg,'info');
							}
							parent.$.messager.progress('close');

						},
						dataType:'json'
					});
				}
			});
		}
	}
	
	
	//导出
	function orderXyExport(){
			parent.$.messager.confirm('询问', '确认导出洗衣订单？', function(b) {
				if (b) { 
					var url = '/xiyiOrderController/exportXiyiOrder';
					var queryData = $.serializeObject($('#searchForm'));
					var index = 0;
					for(var name in queryData) {
						if(index == 0) {
							url += "?";
						}else {
							url += "&";
						}
						url += name + "=" + queryData[name];
						index++;
					}
					window.open(url); 
				}
			}); 
	}
	
	
	
	
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		
		<div data-options="region:'north',title:'查询条件',border:false" style="height: 170px; overflow: hidden;">
			<form id="searchForm">
				<table class="table table-hover table-condensed" style="display: none;">
					<tr>
						<th>洗衣面单</th>
						<td><input name="outBizNum" id="outBizNum" class="span2 " /></td>
					</tr>
					<tr>
						<th>洗衣店</th>
						<td><input name="companyId"   class="span2 companyId" style="width: 155px;" /></td>
					</tr>
					<tr>
						<th>客户电话</th>
						<td><input name="phone" placeholder="客户电话查询" class="span2" /></td>
					</tr>
					<tr>
						<th>订单状态</th>
						<td><select id="ordStatus" name="ordStatus" class="easyui-combobox" style="width: 155px;"  panelHeight=auto>
							<option value="" >--请选择--</option>
							<option value="1" >待处理</option>
							<option value="5" >已取件</option>
							<option value="7" >已送洗</option>
							<option value="8" >待取</option>
							<option value="2" >完成</option>
							<option value="3" >关闭</option>
							<option value="4" >删除</option>
						</select></td>
					</tr>
					<tr>
						<th>支付状态</th>
						<td><select id="paymentStatus" name="paymentStatus" class="easyui-combobox" style="width: 155px;"  panelHeight=auto>
							<option value="" >--请选择--</option>
							<option value="1" >未支付</option>
							<option value="2" >已现金支付</option>
							<option value="3" >已线上支付</option>
						</select></td>
					</tr>
				</table>
			</form>
		</div>
		
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div> 
	</div>
	<div id="toolbar" style="display: none;">
		<a onclick="addMainXiyi();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增订单(代洗衣)</a>
		<a onclick="orderNotice();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-tip'">取件提醒</a>
		<a onclick="orderXyExport();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-redo'">导出订单</a>
		<a href="javascript:void(0);" class="easyui-linkbutton"  data-options="iconCls:'icon-search',plain:true" onclick="searchFun();">提交查询</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="cleanFun();">重置查询</a>
	</div>
		
</body>
</html>